﻿using BenCaoXuan.Infrastructure.Attr;
using BenCaoXuan.Infrastructure.Dto;
using BenCaoXuan.Infrastructure.Dto.Admin.employee;
using BenCaoXuan.Infrastructure.Dto.Admin.System;
using BenCaoXuan.Infrastructure.IOC;
using BenCaoXuan.Service.Instance.admin;
using BenCaoXuan.Service.Interface.admin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BenCaoXuan.Api.Admin.Controllers.admin
{
    [ApiGroup("Admin(管理端模块)")]
  
    public class SysController : BaseController
    {
        private readonly I_Sys_Service _sys_Service;

        public SysController(I_Login_Service login_Service, I_Sys_Service sys_Service) : base(login_Service)
        {
            _sys_Service = sys_Service;
        }



        /// <summary>
        /// 管理端-获取菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Menu() {
            var result =await _sys_Service.Get_Menu();
            return Ok(result);
        
        }

        /// <summary>
        /// 管理端-获取所有的部门
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Department() {
            var result =await _sys_Service.Get_Department();
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取部门下的员工
        /// </summary>
        /// <param name="id"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Dept_Employee(string? id, int page = 1, int limit = 10, string? key = "") {
            var result =await _sys_Service.Get_Dept_Employee(new Fenye_Dto() { 
            id= id,
            limit= limit,
            page= page,
            key= key??""
            });
            return Ok(result);



        }

        /// <summary>
        /// 管理端-获取部门下可选的岗位
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Dept_Post(string? lv) {
            var result =await _sys_Service.Get_Dept_Post(lv);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-新增部门
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Dept(AddDept_Dto dto) {
            var result = await _sys_Service.Add_Dept(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-删除部门
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Dept(Delete_Dto dto) {
            var result =await _sys_Service.Delete_Dept(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取部门下的所有岗位
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DeptPost(string id) {
            var result =await _sys_Service.Get_DeptPost(id);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-新增员工
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Employee(AddEmployee_Dto dto)
        {
            var result = await _sys_Service.Add_Employee(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-编辑员工
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_Employee(UpdateEmployee_Dto dto) {
            var result = await _sys_Service.Update_Employee(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-删除员工
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Employee(Delete_Dto dto) {
            var result = await _sys_Service.Delete_Employee(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-切换员工的账号状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangeIsBan_Employee(IsBan_Dto dto) {
            var result = await _sys_Service.ChangeIsBan_Employee(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取所有的岗位
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_AllPost(int page = 1, int limit = 10, string? key = "") {
            var result = await _sys_Service.Get_AllPost(new Fenye_Dto() { 
            page=page,
            limit=limit,
            key=key??""
            });

            return Ok(result);
        }

        /// <summary>
        /// 管理端-新增岗位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Post(AddPost_Dto dto) {
            var result = await _sys_Service.Add_Post(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取岗位下的人员
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Post_Employee(string id, int page = 1, int limit = 10) {
            var result = await _sys_Service.Get_Post_Employee(new Fenye_Dto() { 
                id=id,
            page=page,
            limit=limit,
            });
            return Ok(result);
        }

        /// <summary>
        /// 管理端-删除岗位
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Post(Delete_Dto dto) {
            var result = await _sys_Service.Delete_Post(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-切换岗位状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangeIsBan_Post(IsBan_Dto dto) {
            var result = await _sys_Service.ChangeIsBan_Post(dto);
            return Ok(result);
                
        }

        /// <summary>
        /// 管理端-获取所有的父级字典数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Dictionary() {
            var result = await _sys_Service.Get_Dictionary();
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取子级字典数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_Children_Dictionary(string? id, int page = 1, int limit = 10, string? key = "") {
            var result = await _sys_Service.Get_Children_Dictionary(new Fenye_Dto() { 
            id=id,
            page=page,
            limit=limit,
            key=key??""
            });
            return Ok(result);
        }

        /// <summary>
        /// 管理端-编辑字典
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Update_Dictionary(UpdateDictionary_Dto dto) {
            var result = await _sys_Service.Update_Dictionary(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-修改字典状态
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> ChangeIsBan_Dictionary(IsBan_Dto dto) {
            var result = await _sys_Service.ChangeIsBan_Dictionary(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-删除字典
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Delete_Dictionary(Delete_Dto dto) {
            var result = await _sys_Service.Delete_Dictionary(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-新增子级字典
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Add_Children_Dictionary(AddChildrenDictionary_Dto dto) {
            var result = await _sys_Service.Add_Children_Dictionary(dto);
            return Ok(result);
        }

        /// <summary>
        /// 管理端-获取需要的字典
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Get_DictionaryByType(string? key)
        {
            var result = await _sys_Service.Get_DictionaryByType(key);
            return Ok(result);
        }

    }
}
